package com.meirengu.webview.utils;


import com.meirengu.webview.utils.ppdai.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PpdaiHttpUtil {

    private static Logger logger = LoggerFactory.getLogger(PpdaiHttpUtil.class);

    //应用id
    private static final String appid = "53a9d9104df642ddac623c07c824ecee";
    //私钥
    private static final String clientPrivateKey = "-----BEGIN PRIVATE KEY-----\n" +
            "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIHEg22aSOcPUyPi\n" +
            "VCqVXp6hw1Akyxkq6FKKH1+jSFPfiAWNaPc7Vfr2JVe1Heb5beazKOUSK8qq7RZg\n" +
            "NxIVOKG6CpvOnNSJwGBT2keU7ko0k9j/iSLocY+fyOTBUh9tvwZUgiePMcS1BnDC\n" +
            "Nu818FnfF5NcMrLEpsKiMeB+wjtpAgMBAAECgYA9+2YnSMU/kCNPBYDcIiJitLM8\n" +
            "qYZUzBjRq+WWYcBfR2qJ9GRJio7j4wQtI3ZX55Wl1rdWytod4IyD3osPWRGGADs4\n" +
            "xYXnSe+YKA6KqMPl9OjPCvV2MC3SoVksU5FORySb3TQOQhJx/CrmYqNZjpqt8DRl\n" +
            "InEbLT9w8pX1BhrR3QJBAPTcamWdtVArs2kboNt6qtL9gYNdaIFILkd7nLBsBdFm\n" +
            "WiT7hNdQh38s1rPhMBazDtpIdw0e5+YthvG8Up98LDMCQQCHq8B2zc0cERz1z+0B\n" +
            "N+ZkusaUIwRo6WNQgGXBNtHHTpjapVDxsYcFaXFAO1zBf/C7sZ4SlwN/69C6MSOf\n" +
            "E53zAkAYRyp9fM+XbV3SlBy05kq9tMj8n2xXNTLxf34ft/YztvRFKnMXbjKhF28K\n" +
            "Us+T0JkuZ3T2ZhQULHtuyH9gtM0lAkBSRg6GPVGYJqyYSMpiRcL67OVFqmKfOIFY\n" +
            "rTSH0jWvFvPNDBmlKFJILuRV3mnmki6rtA+3GEswBRJkBy6h5mSPAkEAuZkS0Rql\n" +
            "FrdCw4nJd6sZakXw/JOlKuOc/sQquod86up5mOFiUk8YrNoF2KR7UjdTiQTG+ZM5\n" +
            "PZR4ntTSiyrBhQ==\n" +
            "-----END PRIVATE KEY-----";


    //公钥
    private static final String serverPublicKey = "-----BEGIN PUBLIC KEY-----\n" +
            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFZA2Q53gGaGuF1yzWUE7og2wC\n" +
            "xoV46EIACKbDu/M3Px2J8T6Er3NaYXKSLQdnDNqK3mv5f9BS/6G7WCBOnaUVTaQ7\n" +
            "RG7NvpLlH/+BL1J0vuc3LmQ/62p33CSX+s74b7kujlUPqe3dWmZ+08YDooe7Zm2E\n" +
            "hzKNdFGv7ZPwRR8PqQIDAQAB\n" +
            "-----END PUBLIC KEY-----";


    static {
        try {
            OpenApiClient.Init(appid, RsaCryptoHelper.PKCSType.PKCS8, serverPublicKey, clientPrivateKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static Result send(String mobile, String name, String idCard) {

        try {
            //授权信息
            AuthInfo authInfo = null;
            //请求url 用户注册接口
            String url = "https://openapi.ppdai.com/marketing/SDKSleepingUserService/CreatLoanBySleepingUser";
            Result result = OpenApiClient.send(url
                    , new PropertyObject("Mobile", mobile, ValueTypeEnum.String)
                    , new PropertyObject("Name", name, ValueTypeEnum.String)
                    , new PropertyObject("IDNum", idCard, ValueTypeEnum.String));
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
